using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;

namespace lt_pmbc_001.DAL
{
	#region using
	using System.Data;
	using lt_pmbc_001.DTO;
	using lt_pmbc_001.Helpers;
    using System.Data.OleDb;
	#endregion

	/// <summary>
	/// Data access object, which get data of ChiTietDiaDiem table from database
	/// </summary>
    public class ChiTietDiaDiemDAL : AbstractDAL
	{
		public ChiTietDiaDiemDAL(string strPath): base(strPath)
		{
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTietDiaDiem_SelectAll";
				base.FillDataSet(ref ds, "ChiTietDiaDiem");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public DataSet SelectByID(string id)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTietDiaDiem_SelectByID";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.VarChar, 1000, id);
				base.FillDataSet(ref ds, "ChiTietDiaDiem");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

		public bool Insert(ChiTietDiaDiemDTO obj)
		{
			try
			{
				base.sql = "usp_ChiTietDiaDiem_Insert";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.VarChar, 1000, obj.ID);
                base.AddParameter("@IDDiaDiem", OleDbType.Integer, 1000, obj.IDDiaDiem);
				base.AddParameter("@Phong", OleDbType.VarChar, 1000, obj.Phong);
                base.AddParameter("@Lau", OleDbType.VarChar, 1000, obj.Lau);
                base.AddParameter("@ToaNha", OleDbType.VarChar, 1000, obj.ToaNha);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public bool Update(ChiTietDiaDiemDTO obj)
		{
			try
			{
				base.sql = "usp_ChiTietDiaDiem_Update";
				base.InitializeCommand();
				base.AddParameter("@IDDiaDiem", OleDbType.Integer, 1000, obj.IDDiaDiem);
				base.AddParameter("@Phong", OleDbType.VarChar, 1000, obj.Phong);
				base.AddParameter("@Lau", OleDbType.VarChar, 1000, obj.Lau);
				base.AddParameter("@ToaNha", OleDbType.VarChar, 1000, obj.ToaNha);
                base.AddParameter("@ID", OleDbType.VarChar, 1000, obj.ID);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public bool Delete(string id)
		{
			try
			{
				base.sql = "usp_ChiTietDiaDiem_Delete";
				base.InitializeCommand();
				base.AddParameter("@ID", OleDbType.VarChar, 1000, id);
				return ExecuteStoredProcedure();
			}
			catch(Exception ex)
			{
                if (ex.InnerException != null)
                {
                    GlobalVariables.Logger.Error(ex.InnerException.Message);
                }
                else
                {
                    GlobalVariables.Logger.Error(ex.Message);
                }
				return false;
			}
		}

		public DataSet SelectByIDDiaDiem(int iddiadiem)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_ChiTietDiaDiem_SelectByIDDiaDiem";
				base.InitializeCommand();
                base.AddParameter("@IDDiaDiem", OleDbType.Integer, 1000, iddiadiem);
				base.FillDataSet(ref ds, "ChiTietDiaDiem");
				return ds;
			}
			catch(System.Exception ex)
			{
				if (ex.InnerException != null)
				{
					GlobalVariables.Logger.Error(ex.InnerException.Message);
				}
				else
				{
					GlobalVariables.Logger.Error(ex.Message);
				}
			}
			finally
			{
				base.CleanUpObject();
			}
			return null;
		}

	}
}